// pages/question-detail/index.js

Page({

  /**
   * 页面的初始数据
   */
  data: {
    datas: "",
    datas_list: "",
    Q_ID: "",
    A_ID: "",
    A_IsCheck:"",
    A_Note: "",
    A_Score: "",
    A_Yintegral: "",
    AImage: "",
    Q_ID: "",
    U_ID: "",
    U_Nickname: "",
    A_IsAnonymity:"0",
    A_Score:"5",
    star1:"1",
    star2: "1",
    star3: "1",
    star4: "1",
    star5: "1",
    U_Headimgurl:"",

    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    A_Score:"5",
    console.log("sssffff");
    console.log(options.dataList);
    console.log(JSON.parse(options.dataList).A_ID);
    var _this = this;
    _this.setData({
      datas_list: JSON.parse(options.dataList),
      A_ID: JSON.parse(options.dataList).A_ID,
      A_IsCheck: JSON.parse(options.dataList).A_Note,
      A_Note: JSON.parse(options.dataList).A_Note,
      A_Score: JSON.parse(options.dataList).A_Score,
      A_Yintegral: JSON.parse(options.dataList).A_Yintegral,
      AImage: JSON.parse(options.dataList).AImage,
      Q_ID: JSON.parse(options.dataList).Q_ID,
      U_ID: JSON.parse(options.dataList).U_ID,
      U_Nickname: JSON.parse(options.dataList).U_Nickname,
      U_Headimgurl: JSON.parse(options.dataList).U_Headimgurl,

    }),

    console.log("2222222");
    console.log(_this.data.AImage);
    console.log("22222222");

      wx.request({
      url: "https://www.chnode.xyz/api/My.ashx?",
        data: {
          DataType: "MyQuestionDetail",
          Q_ID: _this.data.Q_ID,
        },
        success: function (res) {
          console.log("1111");
          console.log(res);
          console.log("11111");
          if (res.data.isok == "false")
            _this.showZanTopTips(res.data.info);
          else {
            _this.setData({
              datas: res.data.data
            })
            console.log(_this.data.datas)
          }
        }
      }),

      wx.request({


      url: "https://www.chnode.xyz/api/My.ashx?",
        data: {
          DataType: "My_Q_Answer",
          Q_ID: _this.data.Q_ID,
        },
        success: function (res) {
          console.log("vvvvvv");
          console.log(res.data.datas[0]);
          console.log("vvvvvv");

          if (res.data.isok == "false")
            _this.showZanTopTips(res.data.info);
          else {
            // _this.setData({
            //   datas_list: res.data.datas
              
            // })
 

          }
        }
      })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  addAddess: function () {
    console.log("click");//
    // wx.navigateTo({
    //   url: "/pages/address-add/index"
    // })
  },

  btnClicked_queren: function (e) {
    var _this = this;
    var temp_index_aid = e.target.dataset.index;
    console.log(temp_index_aid);
    console.log(_this.data.datas_list);
    console.log(_this.data.datas_list[temp_index_aid].A_ID);
    console.log(_this.data.Q_ID);
    wx.showModal({
      content: '确认答案后，将付给回答者相应的积分',
      success: function (res) {
        if (res.confirm) {
          console.log('是');

          /////////

          var _Token;
          try {
            var value = wx.getStorageSync('Token')
            if (value) {
              // Do something with return value
              _Token = value
            }
          } catch (e) {
            // Do something when catch error
          }

          console.log("2222222");
          console.log(_this.data.datas_list[temp_index_aid].A_ID);
          console.log(_Token);
          console.log(_this.data.Q_ID);
          console.log("222222222");

          wx.request({
            url: "https://www.chnode.xyz/api/My.ashx?",
            data: {
              DataType: "ConfirmAnswer",
              A_ID: _this.data.datas_list[temp_index_aid].A_ID,
              Q_UserToken: _Token,
              Q_ID: _this.data.Q_ID,
            },
            success: function (res) {
              console.log(res)
              if (res.data.isok == "false"){
              
              }
                // _this.showZanTopTips(res.data.info);
              else {
                _this.setData({
                  datas_list: res.data.datas
                })
                console.log(_this.data.datas)
              }
            }
          })
          /////////

        } else {
          console.log('否')
        }

      }
    })
  },

  A_IsAnonymity: function (e) {
    var _this = this;
    if (_this.data.A_IsAnonymity == 0){
      _this.setData({
        A_IsAnonymity:"1",
      })
    }else{
      _this.setData({
        A_IsAnonymity: "0",
      })
    }
    console.log(_this.data.A_IsAnonymity)
  },

  btnClicked_pingjia: function (e) {
    console.log(e.target.dataset.index);
  },

  btnClicked_tousu: function (e) {
    console.log(e.target.dataset.index);
  },

  fabu:function(e){
    console.log("dianji123");
    var _this = this;
    var _Token;
    try {
      var value = wx.getStorageSync('Token')
      if (value) {
        // Do something with return value
        _Token = value
      }
    } catch (e) {
      // Do something when catch error
    }
    /////////
    console.log("ssssssss");
    console.log(_this.data.A_ID);
    console.log(_this.data.A_Score);
    console.log(_this.data.A_IsAnonymity);
    console.log(_Token);
    console.log("ssssssssss");


    wx.request({
      url: "https://www.chnode.xyz/api/My.ashx?",
      data: {
        DataType: "AnswerEvaluate",
        A_ID: _this.data.A_ID,
        A_Score: _this.data.A_Score,
        A_IsAnonymity: _this.data.A_IsAnonymity,
        Q_UserToken:_Token
      },
      success: function (res) {
        console.log(res);
        wx.showModal({
          title: '提示',
          content: res.data.info,
          success: function (res) {
            if (res.confirm) {
              console.log('用户点击确定');
              wx.navigateBack({
                delta: 1
              })
            } else if (res.cancel) {
              console.log('用户点击取消')
            }
          }
        })  
        if (res.data.isok == "false"){

        }
         
        else {

        }
      }
    })
          /////////

  },

  star1: function (e) {
    var _this = this;
    _this.setData({
      A_Score: "1",
    })
    if (_this.data.A_Score == 1){
      _this.setData({
        star1: "1",
        star2: "0",
        star3: "0",
        star4: "0",
        star5: "0",
        
      })
    }else{
      _this.setData({
        // star1: "0",
        // star2: "0",
        // star3: "0",
        // star4: "0",
        // star5: "0",
      })
    }
    console.log(_this.data.star1);
  },

  star2: function (e) {
    var _this = this;
    _this.setData({
      A_Score: "2",
    })
    if (_this.data.A_Score == 2) {
      _this.setData({
        star1: "1",
        star2: "1",
        star3: "0",
        star4: "0",
        star5: "0",

      })
    } else {
      _this.setData({
        // star1: "0",
        // star2: "0",
        // star3: "0",
        // star4: "0",
        // star5: "0",
      })
    }
    console.log(_this.data.star2);
  },

  star3: function (e) {
    var _this = this;
    _this.setData({
      A_Score: "3",
    })
    if (_this.data.A_Score == 3) {
      _this.setData({
        star1: "1",
        star2: "1",
        star3: "1",
        star4: "0",
        star5: "0",

      })
    } else {
      _this.setData({
        // star1: "0",
        // star2: "0",
        // star3: "0",
        // star4: "0",
        // star5: "0",
      })
    }
    console.log(_this.data.star3);
  },

  star4: function (e) {
    var _this = this;
    _this.setData({
      A_Score: "4",
    })
    if (_this.data.A_Score == 4) {
      _this.setData({
        star1: "1",
        star2: "1",
        star3: "1",
        star4: "1",
        star5: "0",

      })
    } else {
      _this.setData({
        // star1: "0",
        // star2: "0",
        // star3: "0",
        // star4: "0",
        // star5: "0",
      })
    }
    console.log(_this.data.star4);
  },

  star5: function (e) {
    var _this = this;
    _this.setData({
      A_Score: "5",
    })
    if (_this.data.A_Score == 5) {
      _this.setData({
        star1: "1",
        star2: "1",
        star3: "1",
        star4: "1",
        star5: "1",

      })
    } else {
      _this.setData({
        // star1: "0",
        // star2: "0",
        // star3: "0",
        // star4: "0",
        // star5: "0",
      })
    }
    console.log(_this.data.star5);
  },

})